


//////// load "hk_immi_survey.dta"

//// drop outliers
drop if Duration < 5 | Duration > 60

/// gen variables
egen attitude = rfirst(control_a econ_a cul_a fam_a pol_a)
egen policy = rfirst(control_p econ_p cul_p fam_p pol_p)

/// balance test ---- results shown in Table C1
tabulate gender group, chi2
tabulate edu group, chi2
tabulate income_new group, chi2
tabulate born group, chi2
anova age group
by group: sum age
anova q74 group

///t-test
sort group
by group: sum attitude
by group: sum policy

// economic vs control 
gen group1 = group
replace group1 = . if group == 3 | group == 4 | group == 5

//social norm vs control
gen group2 = group
replace group2 = . if group == 2 | group == 4 | group == 5

//family history vs control
gen group3 = group
replace group3 = . if group == 2 | group == 3 | group == 5

//family history vs control
gen group4 = group
replace group4 = . if group == 2 | group == 3 | group == 4

//t test for each group ------ results shown in Figure 6, Table C2
ttest attitude, by(group1) //by(group2) by(group3) by(group4)
ttest policy, by(group1) //by(group2) by(group3) by(group4)

//////// load "group_econ.dta"/"group_social.dta"/"group_family.dta"/"group_politics.dta"


//sub-ttest, using split dataset ----- results shown in Figure 8, Figure C2, Figure C3
//group_econ: control vs. economic contribution
//group_social: control vs. social norms
//group_family: control vs. family history
//group_politics: control vs. democratic values

ttest attitude, by(group), if edu == 1
ttest attitude, by(group), if edu == 0
ttest attitude, by(group), if income_new == 1
ttest attitude, by(group), if income_new == 2
ttest attitude, by(group), if income_new == 3
ttest attitude, by(group), if born == 1
ttest attitude, by(group), if born == 2
ttest attitude, by(group), if born == 3

ttest policy, by(group), if edu == 1
ttest policy, by(group), if edu == 0
ttest policy, by(group), if income_new == 1
ttest policy, by(group), if income_new == 2
ttest policy, by(group), if income_new == 3
ttest policy, by(group), if born == 1
ttest policy, by(group), if born == 2
ttest policy, by(group), if born == 3


//////// load "group_politics.dta"

/// regression using group_politics subsample ---- results shown in Figure 7, Table C3

asdoc reg policy i.group, r replace nest
asdoc reg policy i.group age gender i.edu i.income_new i.born parent q74, r save(JE) nest
// weighted regression
asdoc reg policy i.group age gender i.edu i.income_new i.born parent q74 [pweight= weight_2], r save(JE) nest

asdoc logit policy_new i.group, r  level(90) save(JE) nest
asdoc logit policy_new i.group age gender i.edu i.income_new i.born parent q74, r save(JE) nest
// weighted regression
asdoc logit policy_new i.group age gender i.edu i.income_new i.born parent q74 [pweight= weight_2], r save(JE) nest

reg policy i.group, r level(90) 
reg policy i.group age gender i.edu i.income_new i.born parent q74, r level(90)
reg policy i.group age gender i.edu i.income_new i.born parent q74 [pweight= weight_2], r level(90)
logit policy_new i.group, r
margins, dydx(group) atmeans
margins, dydx(group) atmeans level(90)
logit policy_new i.group age gender i.edu i.income_new i.born parent q74, r
logit policy_new i.group age gender i.edu i.income_new i.born parent q74 [pweight= weight_2], r 

//interactive experience ---- results shown in Figure C1
reg policy i.group##c.q74 age gender i.edu i.income_new i.born parent, r level(90)
margins, dydx(group) at(q74=(0(1)10)) level(90)


//////// load "hk_topic_raw.dta"

/// RDiT analysis of news reports on mainland immigrants ----- results shown in Figure B3, Table B4
/// using "hk_topic_raw.dta" 
gen week_new = weekly(weekly, "YW")
format %tw week_new

egen newspaperid = group(newspaper), label lname(newspaper)

xtset newspaperid week_new

//figure B3
//umbrella movement

drop if week_new < tw(2013w1)
drop if week_new > tw(2016w52)

rdrobust topic_1 week_new, c(2852) covs(newspaperid) vce(cluster newspaperid) //2014w45
cmogram topic_1 week_new, cut(2852)  scatter lineat(2852) lfit

rdrobust topic_2 week_new, c(2852) covs(newspaperid) vce(cluster newspaperid)
cmogram topic_2 week_new, cut(2852) scatter lineat(2852) lfit


//anti-elab protest

drop if week_new < tw(2018w1)

rdrobust topic_1 week_new, c(3091) covs(newspaperid) vce(cluster newspaperid) //2019w24
cmogram topic_1 week_new, cut(3091) scatter lineat(3091) lfit

rdrobust topic_2 week_new, c(3091) bwselect(msesum) covs(newspaperid) vce(cluster newspaperid) 
cmogram topic_2 week_new, cut(3091) scatter lineat(3091) lfit



